function Application() {

	this.user = null;
	this.book = null;
	var tabsDiv = 'mainPanel';
	var errorDiv = 'errorPanel';

	this.authController = new AuthController(this, 'loginForm');
	this.userView = new UserView(this.authController, '#userInfo');
	this.booksManager = new BooksManager(this, '#books');
	this.currencyManager = new CurrencyManager(this, '#currencies');
	this.categoryManager = new CategoryManager(this, '#categories');
	this.accountManager = new AccountManager(this, '#accounts');
	this.tagManager = new TagManager(this);
	this.trManager = new TrManager(this, 'trTable', 'trForm', 'trFilter');
	this.reportController = new ReportController(this, 'reports');
	this.notificationView = new NotificationView('#notification');
	this.errorView = new ErrorView(errorDiv);

	this.renderNotification = function(message, showProgress, timeout) {
		this.notificationView.show(message, showProgress, timeout);
	};

	this.showNotification = function(message, timeout) {
		this.renderNotification(message, false, timeout);
	};

	this.showWarning = function(message, timeout) {
		this.renderNotification(message, false, timeout);
	};

	this.showProgress = function(message) {
		this.renderNotification(message, true, 0);
	};

	this.cleanNotification = function() {
		this.notificationView.clean();
	};

	this.showError = function(title, message) {
		this.cleanNotification();
		this.errorView.render(title, message);
		el(tabsDiv).css('display', 'none');
	};

	this.init = function() {
//		console.log('Application.init');
		var tabs = el(tabsDiv);
		tabs.jqxTabs({ width: window.innerWidth - 20, height: window.innerHeight - 90, position: 'top', theme: 'spotem' });
		var tabToSelect = $.jqx.cookie.cookie('activeTab');
		tabToSelect = (tabToSelect != null)? parseInt(tabToSelect): 1;
		tabs.jqxTabs('select', tabToSelect);
		tabs.on('selected', function (event) {
			$.jqx.cookie.cookie('activeTab', event.args.item);
		});

		$(window).bind('resizeEnd', function() {
			tabs.jqxTabs({ width: window.innerWidth - 20, height: window.innerHeight - 90 });
		});
		this.authController.getCurrentUser();
	};

	this.setUser = function(user) {
		this.user = user;
		this.book = null;
		if(user == null) {
			this.authController.view.render();
		} else {
			this.errorView.hide();
			el(tabsDiv).css('display', 'block');
			this.booksManager.loadBooks(user.id);
		}
	};

	this.setBook = function(book) {
		var result = !areSame(this.book, book);
		this.book = book;
		var tabTitle = 'Книга';
		if(book != null) {
			tabTitle += ': <b>' + book.name + '</b>';
			this.categoryManager.loadCategories(book.id);
			this.currencyManager.loadCurrencies(book.id);
			this.accountManager.loadAccounts(book.id);
			this.tagManager.loadTags(book.id);
			this.trManager.loadTransactions(book.id);
		}
		$('#bookTab').html(tabTitle);
		return result;
	};
};